<?php
/**
 * 用户
 * @author gary
 **/
class Services_Auth_Tealogin extends Fend
{

    private $_memcache = '';
    public static function factory()
    {
        return new self();
    }

    public function __construct()
    {
        $config = Fend_Di::factory()->get('memcacheconfig');
        $this->_memcache =new \memcache;;
        $this->_memcache->connect($config['teasess']['host'], $config['teasess']['port']);
    }

    /**
     * 登录校验
     * teacher: {"token":"bc6e94ff791a00c201ea6feb3fd8b2cc","adminId":"10175","adminName":"zhangzhongxiang","realname":"张中祥","email":"zhangzhongxiang@100tal.com","avatar":"","department":"","grade_ids":"","area_id":"0","subject_id":"0","division_id":"0","teacherId":"2170","counselorId":"2172","depIds":["44066972"],"roleIds":[],"appId":0,"permissions":[],"menu":[],"domain":[],"teacher_username":"张中祥","teacher_user_id":"2170","teacher_spell":"zhangzhongxiang","teacher_email":"zhangzhongxiang@100tal.com","teacher_grade_ids":"1","teacher_grade_names":"幼升小","teacher_grade_digits":"1","teacher_subject_ids":"23","teacher_subject_names":"","teacher_subject_digits":"4194304","user_id":"10175","username":"zhangzhongxiang"}
     * student: {"time":1521774454,"uid":"30079","user_id":"30079","role":"1","signature":"371650d0c7117ca0584b8346b53b1a77","modify_time":1522232038,"rs_time":1522231367,"source_type":1,"userName":"x01@qq.com","userId":"30079","curGrade":2,"curGradeAlias":"xiao1","stuName":"男犇猋骉长长"}
     */
    public function checkLogin($cookie='')
    {
        $wx = !empty($cookie)?$cookie:'';
        $wx = !empty($_COOKIE['teacher'])?$_COOKIE['teacher']:$wx;
        if(empty($wx)){
            return false;
        }
        $string =$this->_memcache->get($wx);
        if(empty($string)){
            return false;
        }

        $uinfo = Fend_Func::load()->unserialize_php($string);

        if (!$uinfo) {
            return false;
        }

        Fend_Di::factory()->set('user_info',$uinfo);
        return $uinfo;
    }
}
